package com.hmall.trade.listener;

import com.hmall.trade.domain.po.Order;
import com.hmall.trade.service.IOrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties;
import org.springframework.stereotype.Component;
@Slf4j
@Component
@RequiredArgsConstructor
public class PayStatusListener {
    private  final IOrderService orderService;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name="trade.pay.success.queue",durable = "true"),
            exchange = @Exchange(name = "pay.direct",type = ExchangeTypes.DIRECT),
            key="pay.success"
    ))
    public  void listenPaySuccess( Long orderId){
        Order order = orderService.getById(orderId);
        if(order ==null || order.getStatus()!=1){
            return ;
        }
        orderService.markOrderPaySuccess(orderId);

    }
}
